﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScheduleMaker.DB.Domain;
using ScheduleMaker.DB.Domain.Core;

namespace ScheduleMaker.DB.CoreDAO
{
    public class LevelDAO : CoreAbstractDAO<Level>
    {
        private AdapterAbstractDAO<Level, LevelSchool> wrappedAbstractDAOSchool;
        private AdapterAbstractDAO<Level, LevelUniversity> wrappedAbstractDAOUniversity;
        private LevelDAOSchool wrappedDAOSchool;
        private LevelDAOUniversity wrappedDAOUniversity;

        public LevelDAO(LevelDAOSchool wrappedDAOSchool)
        {
            this.wrappedDAOSchool = wrappedDAOSchool;
            this.wrappedAbstractDAOSchool =
                new AdapterAbstractDAO<Level, LevelSchool>((AbstractDAO<LevelSchool>)wrappedDAOSchool);
        }

        public LevelDAO(LevelDAOUniversity wrappedDAOUniversity)
        {
            this.wrappedDAOUniversity = wrappedDAOUniversity;
            this.wrappedAbstractDAOUniversity =
                new AdapterAbstractDAO<Level, LevelUniversity>((AbstractDAO<LevelUniversity>)wrappedDAOUniversity);
        }

        public Level getByName(String name)
        {
            Level Level;
            if (wrappedDAOSchool != null)
            {
                Level = wrappedDAOSchool.getByName(name);

            }
            else if (wrappedDAOUniversity != null)
            {
                Level = wrappedDAOUniversity.getByName(name);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped LevelDAOSchool nor LevelDAOUniversity was initialized");
            }
            return Level;
        }

        public override void update(Level entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.update(entity);
            }
            else if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.update(entity);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped LevelDAOSchool nor LevelDAOUniversity was initialized");
            }
        }

        public override void save(Level entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.save(entity);
            }
            else if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.save(entity);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped LevelDAOSchool nor LevelDAOUniversity was initialized");
            }
        }

        public override void saveOrUpdate(Level entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.saveOrUpdate(entity);
            }
            else if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.saveOrUpdate(entity);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped LevelDAOSchool nor LevelDAOUniversity was initialized");
            }
        }

        public override void delete(Level entity)
        {
            if (wrappedDAOSchool != null)
            {
                wrappedAbstractDAOSchool.delete(entity);
            }
            else if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.delete(entity);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped LevelDAOSchool nor LevelDAOUniversity was initialized");
            }
        }

        public override Level getById(int id)
        {
            Level entity;
            if (wrappedDAOSchool != null)
            {
                entity = wrappedAbstractDAOSchool.getById(id);
            }
            else if (wrappedDAOUniversity != null)
            {
                entity = wrappedAbstractDAOUniversity.getById(id);
            }
            else
            {
                throw new NotImplementedException("Neither wrapped LevelDAOSchool nor LevelDAOUniversity was initialized");
            }

            return entity;
        }

        public override IList<Level> getAll()
        {
            IList<Level> records;
            if (wrappedDAOSchool != null)
            {
                records = wrappedAbstractDAOSchool.getAll();
            }
            else if (wrappedDAOUniversity != null)
            {
                records = wrappedAbstractDAOUniversity.getAll();
            }
            else
            {
                throw new NotImplementedException("Neither wrapped LevelDAOSchool nor LevelDAOUniversity was initialized");
            }

            return records;
        }
    }
}
